package com.xqzgj.bill.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xqzgj.common.annotation.Log;
import com.xqzgj.common.core.controller.BaseController;
import com.xqzgj.common.core.domain.AjaxResult;
import com.xqzgj.common.enums.BusinessType;
import com.xqzgj.bill.domain.Expense;
import com.xqzgj.bill.service.IExpenseService;
import com.xqzgj.common.utils.poi.ExcelUtil;
import com.xqzgj.common.core.page.TableDataInfo;

/**
 * 支出记录Controller
 * 
 * @author zhoujiam
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/bill/expense")
public class ExpenseController extends BaseController
{
    @Autowired
    private IExpenseService expenseService;

    /**
     * 查询支出记录列表
     */
    @PreAuthorize("@ss.hasPermi('bill:expense:list')")
    @GetMapping("/list")
    public TableDataInfo list(Expense expense)
    {
        startPage();
        List<Expense> list = expenseService.selectExpenseList(expense);
        return getDataTable(list);
    }

    /**
     * 导出支出记录列表
     */
    @PreAuthorize("@ss.hasPermi('bill:expense:export')")
    @Log(title = "支出记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Expense expense)
    {
        List<Expense> list = expenseService.selectExpenseList(expense);
        ExcelUtil<Expense> util = new ExcelUtil<Expense>(Expense.class);
        util.exportExcel(response, list, "支出记录数据");
    }

    /**
     * 获取支出记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('bill:expense:query')")
    @GetMapping(value = "/{expenseId}")
    public AjaxResult getInfo(@PathVariable("expenseId") Long expenseId)
    {
        return success(expenseService.selectExpenseByExpenseId(expenseId));
    }

    /**
     * 新增支出记录
     */
    @PreAuthorize("@ss.hasPermi('bill:expense:add')")
    @Log(title = "支出记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Expense expense)
    {
        return toAjax(expenseService.insertExpense(expense));
    }

    /**
     * 修改支出记录
     */
    @PreAuthorize("@ss.hasPermi('bill:expense:edit')")
    @Log(title = "支出记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Expense expense)
    {
        return toAjax(expenseService.updateExpense(expense));
    }

    /**
     * 删除支出记录
     */
    @PreAuthorize("@ss.hasPermi('bill:expense:remove')")
    @Log(title = "支出记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expenseIds}")
    public AjaxResult remove(@PathVariable Long[] expenseIds)
    {
        return toAjax(expenseService.deleteExpenseByExpenseIds(expenseIds));
    }
}
